<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>后台管理系统登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css">
    <link rel="stylesheet" href="/admin/css/login.css">
    <link rel="stylesheet" href="/css/login.css">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/jquery.i18n.properties.min.js"></script>
    <script src="/js/util.js"></script>
    <!--<script src="js/layui/layui.all.js"></script>-->

    <style>
        .layui-anim-upbit {
            color: #000000 !important;
        }
    </style>
</head>
<body class="en">
<div class="user-login user-display-show" id="user-login">
    <div class="loginForm layui-bg-black" style="position: relative;left: 50%;transform: translateX(-50%);">
        <div class="user-login-main" id="adminlogin_div">
            <div class="user-login-box user-login-header">
                <h3 data-lang="login_shop_houtai">商城后台管理系统</h3>
            </div>
            <div class="user-login-header">
                <a style="color:#bff5bc;" href="#" onclick="changelogin(1)">（点击切换到客服登陆）</a>
            </div>
            <div class="user-login-box user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="LAY-user-login-username" placeholder="用户名"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" placeholder="密码"
                           class="layui-input">
                </div>

                <div class="layui-form-item">
                    <button id="loginBtn" class="layui-btn layui-btn-fluid" lay-submit
                            lay-filter="LAY-user-login-submit" data-lang="login_in">登 入
                    </button>
                </div>

            </div>
        </div>

        <div class="user-login-main" id="kefulogin_div" style="display: none">
            <div class="user-login-box user-login-header">
                <h3 data-lang="login_shop_houtai">商城客服系统登录</h3>
            </div>
            <div class="user-login-header">
                <a style="color:#bff5bc;" href="#" onclick="changelogin(2)">（点击切换到管理员后台登陆）</a>
            </div>
            <div class="user-login-box user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username2" id="LAY-user-login-username2" placeholder="客服名"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password2" id="LAY-user-login-password2" placeholder="密码"
                           class="layui-input">
                </div>

                <div class="layui-form-item">
                    <button id="loginBtn2" class="layui-btn layui-btn-fluid" lay-submit
                            lay-filter="LAY-user-login-submit" data-lang="login_in2">登 入
                    </button>
                </div>

            </div>
        </div>
    </div>
    <div class="layui-trans user-login-footer">
        <p>© 2021 <a href="#" target="_blank" data-lang="login_shop_houtai">商城后台管理系统</a></p>
    </div>
</div>
<script src="/js/layui/layui.all.js"></script>
<!--<script src="/admin/js/login.js"></script>-->
<script>

    var layer = layui.layer;
    var form = layui.form;
    var login_type = 1;
    var path = getRootPath();
    var $ = layui.$;

    //得到工程路径
    function getRootPath() {
        //http://localhost:8083/uimcardprj/share/meun.jsp
        var curWwwPath = window.document.location.href;
        //uimcardprj/share/meun.jsp
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        //http://localhost:8083
        var localhostPaht = curWwwPath.substring(0, pos);
        // uimcardprj
        var projectName = pathName
            .substring(0, pathName.substr(1).indexOf('/') + 1);
        if (projectName == "/admin" || projectName == "/static" || projectName == "/weixin" || projectName == "/business")
            projectName = "";

        return (projectName);
    }

    $("#loginBtn").click(function () {
        var username = $("#LAY-user-login-username").val();
        var password = $("#LAY-user-login-password").val();
        if (username == null || username == '') {
            layer.msg("用户名不能为空");
            return;
        }
        if (password == null || password == '') {
            layer.msg("密码不能为空");
            return;
        }
        if (login_type == 1) {
            $.ajax({
                url: '/admin/login',
                type: 'post',
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    if (data.code == 200) {
                        //sessionStorage    会话结束的时候,sessionStorage中的键值对会被清空
                        //localStorage      将第一次请求的数据直接存储到本地，这个相当于一个5M大小的针对于前端页面的数据库，相比于cookie(4K)可以节约带宽，但是这个却是只有在高版本的浏览器中才支持的
                        sessionStorage.setItem("admin_id", data.data.id);
                        sessionStorage.setItem("admin_name", data.data.username);
                        sessionStorage.setItem("admin",data.data);
                        layer.msg("登录成功", {
                                time: 2000,
                                end: function () {
                                    // alert("登录成功");
                                    window.location.href = "/admin/main.html";
                                }
                            }
                        );
                    } else {
                        layer.msg(data.msg, {time: 2000});
                    }
                },
                erorr: function () {
                    layer.msg("网络异常");
                }
            });
        } else {
            $.ajax({
                url: '/login/wuye',
                type: 'post',
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("登录成功", {
                                time: 2000,
                                end: function () {
                                    window.location.href = "/admin/wuye.html";
                                }
                            }
                        );
                    } else {
                        layer.msg(data.msg, {time: 2000});
                    }
                }
                ,
                erorr: function () {
                    layer.msg("网络异常");
                }
            });
        }
    });

    $("#LAY-user-login-password").keypress(function (event) {
        if (event.which === 13) {
            $('#loginBtn').click();
        }
    })

    $("#loginBtn2").click(function () {
        var kefuname = $("#LAY-user-login-username2").val();
        var password = $("#LAY-user-login-password2").val();
        if (kefuname == null || kefuname == '') {
            layer.msg("客服名不能为空");
            return;
        }
        if (password == null || password == '') {
            layer.msg("密码不能为空");
            return;
        }
        if (login_type == 1) {
            $.ajax({
                url: '/kefu/kefuLogin',
                type: 'post',
                data: {
                    kefuName: kefuname,
                    password: password
                },
                success: function (data) {
                    if (data.code == 200) {
                        //sessionStorage    会话结束的时候,sessionStorage中的键值对会被清空
                        //localStorage      将第一次请求的数据直接存储到本地，这个相当于一个5M大小的针对于前端页面的数据库，相比于cookie(4K)可以节约带宽，但是这个却是只有在高版本的浏览器中才支持的
                        sessionStorage.setItem("kefu_id", data.data.id);
                        sessionStorage.setItem("kefu_name", data.data.kefuName);
                        sessionStorage.setItem("areaId", data.data.areaId);
                        layer.msg("登录成功", {
                                time: 2000,
                                end: function () {
                                    window.location.href = "/admin/kefumain.html";
                                }
                            }
                        );
                    } else {
                        layer.msg(data.msg, {time: 2000});
                    }
                },
                erorr: function () {
                    layer.msg("网络异常");
                }
            });
        }
    });

    $("#LAY-user-login-password2").keypress(function (event) {
        if (event.which === 13) {
            $('#loginBtn2').click();
        }
    })

    form.on("select(login)", function (res) {
        login_type = res.value
    })

    function changelogin(ind) {
        if (ind == 1) {
            $("#kefulogin_div").css("display", "block");
            $("#adminlogin_div").css("display", "none");
        } else {
            $("#kefulogin_div").css("display", "none");
            $("#adminlogin_div").css("display", "block");
        }
    }

</script>
</body>
</html>